package com.qding.park.manager.service.core.biz;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.github.pagehelper.PageHelper;
import com.qding.park.common.utils.DateUtils;
import com.qding.park.manager.cache.UserCacheInter;
import com.qding.park.manager.pojo.TbHistoryRecord;
import com.qding.park.manager.pojo.TbUserInfo;
import com.qding.park.manager.pojo.enums.UserTypeEnum;
import com.qding.park.manager.pojo.example.HisExample;
import com.qding.park.manager.service.core.mapper.TbCarMapper;
import com.qding.park.manager.service.core.mapper.TbHistoryRecordMapper;
import com.qding.park.manager.service.core.mapper.TbUserInfoMapper;

@Component("historyBiz")
public class HistoryBiz {

	@Autowired
	private TbCarMapper tbCarMapper;
	
	@Autowired
	private TbUserInfoMapper  tbUserInfoMapper;
	
	@Autowired
	private UserCacheInter userCacheInter;
	
	@Autowired
	private TbHistoryRecordMapper tbHistoryRecordMapper;
	
/*	public static class OtherCriteria{
		
		private int otherUserid;
		
		private Date boundary;

		public int getOtherUserid() {
			return otherUserid;
		}

		public void setOtherUserid(int otherUserid) {
			this.otherUserid = otherUserid;
		}

		public Date getBoundary() {
			return boundary;
		}

		public void setBoundary(Date boundary) {
			this.boundary = boundary;
		}
		
		
	}*/
	
	/** 
	 * @param userId  用户id
	 * @param recordType  记录类型
	 * @param jumpPage  当前页码
	 * @param pageLength  页长度
	 * @return
	 */
	public List<TbHistoryRecord> recordList(String bjuserid,int recordType,int jumpPage,int pageLength){
		TbUserInfo tbUserInfo = tbUserInfoMapper.queryUseByBjuseridType(bjuserid, UserTypeEnum.REGISTER_USER.getType());
		int userId = tbUserInfo.getId();
		
		HisExample example=new HisExample();
		example.setUserId(userId);
		List<HisExample.OtherUser> otherExamples=tbUserInfoMapper.otherHisExample(userId);
		example.setOthers(otherExamples);
		List<TbHistoryRecord> list=new ArrayList<TbHistoryRecord>();
		PageHelper.startPage(jumpPage, pageLength);
		
//		List<TbCar> cars=tbCarMapper.queryMyCars(userId);
//		if(ListUtil.isEmpty(cars)){
//			return list;
//		}
		
		Date  boundaryDate=DateUtils.addMonths(new Date(), -3);
		if(tbUserInfo.getCreate_date()!=null){
			boundaryDate=boundaryDate.getTime()<tbUserInfo.getCreate_date().getTime()?tbUserInfo.getCreate_date():boundaryDate;
		}
		
//		list=tbHistoryRecordMapper.queryPage(userId, recordType, boundaryDate);
		list=tbHistoryRecordMapper.queryPageByExample(example,recordType,boundaryDate);
		
//		if(recordType == TbHistoryRecord.RecordTypeEnum.MONTHRENT_PAY.getCode()){
//			//月租单
//			list=tbHistoryRecordMapper.queryMonthPage(userId, cars, boundaryDate);
//		}else if(recordType == TbHistoryRecord.RecordTypeEnum.RESERVE_PAY.getCode()){
//			//预定单
//			list=tbHistoryRecordMapper.queryReservePage(userId, cars, boundaryDate);
//		}else if(recordType == TbHistoryRecord.RecordTypeEnum.TEMP_PAY.getCode()){
//			//临停单
//			list=tbHistoryRecordMapper.queryTempPage(userId, cars, boundaryDate);
//		}else if(recordType == TbHistoryRecord.RecordTypeEnum.ALL_PAY.getCode()){
//			//所有的类型
//			tbHistoryRecordMapper.queryAllPayPage(userId, cars, boundaryDate);
//		}
		
		
		return list;
	}
}
